package br.sed.theenemy.presentation.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.sed.theenemy.business.exception.DBException;
import br.sed.theenemy.business.exception.HashNotValidException;
import br.sed.theenemy.business.services.Services;

/**
 * Servlet implementation class activeUser
 */
@WebServlet("/activeUser")
public class activeUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public activeUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Services services = Services.getInstance();

		String hash = request.getParameter("hash");

		try {
			services.activateUser(hash);
			response.sendRedirect("login.do?method=activated");
		} catch (HashNotValidException e) {
			response.sendRedirect("activate.jsp?answer=erro");
		} catch (DBException e) {
			response.sendRedirect("activate.jsp?answer=erro");
		} 
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
